{include file="public/layout" /}
<style type="text/css">
.yes {
    color: #1BBC9D;
    cursor: default;
} 
</style>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 
  <span class="c-gray en">&gt;</span> 商品管理 
  <span class="c-gray en">&gt;</span> 商品列表
  <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
    <i class="Hui-iconfont">&#xe68f;</i>
  </a>
  </nav>
<div class="page-container">
  <form action="{:url('Admin/goods/goodsList')}" method="post">
  <div class="text-c"> 日期范围：
    <input type="text" onfocus="WdatePicker()" id="datemin" name="start_time" class="input-text Wdate" style="width:120px;" value="{$stime|date='Y-m-d'}">
    -
    <input type="text" onfocus="WdatePicker()" id="datemax" name="end_time" class="input-text Wdate" style="width:120px;" value="{$etime|date='Y-m-d'}">
    <input type="text" class="input-text" style="width:250px;" placeholder="输入商品标题、IID" name="keyword">
    <select name="cate_id" style="width:5%;height:1.9rem;box-sizing: border-box;border: solid 1px #ddd;">
      <option value="0">全部</option>
      {if isset($category)}
        {foreach name="category" item="vo"}
          <option value="{$vo.id}">{$vo.name}</option>
        {/foreach}
      {/if}
    </select>
    <button type="submit" class="btn btn-success radius"><i class="Hui-iconfont">&#xe665;</i> 搜商品</button>&nbsp;&nbsp;&nbsp;
  </div>
    </form>
  <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l">
    <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
    <a href="/Admin/goods/addEditGoods" class="btn btn-primary radius"><i class="Hui-iconfont"></i> 添加商品</a>
   </span> <span class="r">共有数据：<strong>{$count}</strong> 条</span> </div>
  <div class="mt-20">
  <table class="table table-border table-bordered table-hover table-bg table-sort">
    <thead>
      <tr class="text-c">
        <th width="25"><input type="checkbox"></th>
        <th width="80">ID</th>
        <th width="100">商品图片</th>
        <th width="100">商品标题</th>
        <th width="100">分类</th>
        <th width="100">原价</th>
        <th width="100">折扣价</th>
        <th width="100">销量</th>
        <th width="100">店铺</th>
        <th width="100">推荐</th>
        <th width="130">添加时间</th>
        <th width="130">排序</th>
        <th width="100">操作</th>
      </tr>
    </thead>
    <tbody>
      {if $list}
      {foreach name="list" item="vo" key="k" }
        <tr class="text-c">
          <td><input type="checkbox" value="{$vo.goods_id}" class="checkboxId"></td>
          <td>{$vo.goods_id}</td>
           <td align="center">
              <img src="{$vo.pic_url}" style="width: 50px !important; height: 50px !important;">
          </td>
          <td>{if isset($vo.title)}{$vo.title}{/if}</td>
          <td>{$vo.name}</td>
          <td>{$vo.price}</td>
          <td>{$vo.discount_price}</td>
          <td>{$vo.volume}</td>
          <td>
              {if $vo.shop_type == 'C'}淘宝{/if}
              {if $vo.shop_type == 'T'}天猫{/if}
              {if $vo.shop_type == 'D'}京东{/if}
              {if $vo.shop_type == 'P'}拼多多{/if}
          </td>
          <td>
            <span class="yes">
            {if $vo.is_recommend == 1}
                <span class="yes" onClick="changeTableVal('goods','goods_id','{$vo.goods_id}','is_recommend',this)" ><i class="fa fa-check-circle"></i>是</span>
                {else /}
                <span class="no" onClick="changeTableVal('goods','goods_id','{$vo.goods_id}','is_recommend',this)" ><i class="fa fa-ban"></i>否</span>
            {/if}
            </span>
          </td>
          <td>{$vo.add_time|date="Y-m-d H:i:s"}</td>
          <td>{$vo.order_sort}</td>
          <td class="td-manage">
           <a title="编辑" href="/Admin/goods/addEditGoods?id={$vo.goods_id}" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont"></i></a>
           <a title="删除" href="javascript:;" data-url="{:U('user/del')}" onclick="_del(this,{$vo.goods_id})" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
          </td>
        </tr>
        {/foreach}
        {/if}
    </tbody>
  </table>
  <div>{$list->render()|raw}</div>
  </div>
</div>
{include file="public/footer" /}
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/public/h-ui.admin/lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="/public/h-ui.admin/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
/*用户-查看*/
function member_show(title,url,id,w,h){
  layer_show(title,url,w,h);
}

/*删除*/
function _del(obj,id){
  layer.confirm('确认要删除吗？',function(index){
    $.ajax({
      type: 'POST',
      url: $(obj).attr('data-url'),
      data:{ids: id},
      dataType: 'json',
      success: function(data){
        $(obj).parents("tr").remove();
        layer.msg('已删除!',{icon:1,time:1000});
      },
      error:function(data) {
        console.log(data.msg);
      },
    });   
  });
}

//批量删除
  function datadel() {
    var ids = '';
    var len = $(".checkboxId").length;
    for(var i = 0; i < len; i++) {
      var status = $(".checkboxId").eq(i).prop("checked");
      if(status == true) {
        var checkval = 1;
        ids+= ','+$(".checkboxId").eq(i).val();
      }
    }

    //至少选择一项目
    if(checkval == 1) {
      var ids = ids.substring(1);
      layer.confirm('确认要删除吗？',function(index){
        $.ajax({
            type: 'POST',
            url: '/Admin/user/delAll',
            data : {act:'delAll',ids:ids},
            dataType: 'json',
            success: function(data){
              layer.msg('已删除!',{icon:1,time:1000});
              setTimeout(function(){window.location.reload();}, 2000);
            },
            error:function(data) {
              console.log(data.msg);
            },
        });   
      });
    } else {
      layer.msg('至少选择一项目!',{icon:2,time:1000});
    }
  }
</script> 
</body>
</html>